import Service from './$axios'
const appName = 'lw-mes-file'
// 上传文件(单文件)
export const uploadFile = async (da) => {
  const data = new FormData;
  await data.append('file', da)
  return Service({
    url: `${appName}/file/uploadFile`,
    method: 'post',
    params: { userId: localStorage.getItem('userId') },
    headers: {
      "Content-Type": "multipart/form-data",
    },
    data
  })
}
// 上传文件(多文件)
export const uploadFileArray = async (da) => {
  const data = new FormData;
  for (var item of da) {
    await data.append('files', item)
  }
  return Service({
    url: `${appName}/file/uploadFileArray`,
    params: { userId: localStorage.getItem('userId') },
    method: 'post',
    headers: {
      "Content-Type": "multipart/form-data",
    },
    data
  })
}
// 查询文件
export const queryFilePage = async (data) => {
  return Service({
    url: `${appName}/file/queryFilePage?${data}`,
    method: 'get',
  })
}
// 根据文件id获取文件详情
export const queryFileId = async (fileId) => {
  return Service({
    url: `${appName}/file/queryFileId/${fileId}`,
    method: 'get',
  })
}
// 根据id获取文件流
export const queryFileStream = async (fileId) => {
  return Service({
    url: `${appName}/file/queryFileStream/${fileId}`,
    method: 'get',
  })
}
// 根据id下载文件
export const downloadFile = async (fileId) => {
  return Service({
    url: `${appName}/file/downloadFile/${fileId}`,
    method: 'get',
    responseType: 'blob'
  })
}
// 根据文件id删除文件
export const deleteFile = async (fileId) => {
  return Service({
    url: `${appName}/file/deleteFile/${fileId}`,
    method: 'delete',
  })
}